import enum

import pygame

from Action.Walk import DirWalkByAImage


class ShootDir(enum.IntEnum):
    not_shoot = 0
    left_down = 1
    right_down = 2
    left_up = 3
    right_up = 4
    up = 5
    down = 6


class DirShootByAImage(DirWalkByAImage):
    '''
    一张图 4*4人物  左蹲射击， 右蹲射击，左站射击，右站射击
    '''
    image_count = 16
    image_col = 4
    image_width = 49
    image_height = 74
    shoot_dir = ShootDir.left_up

    @staticmethod
    def __init_shoot(up_image_path, down_image_path):
        """
        初始化射击图片
        :param up_image_path:
        :param down_image_path:
        :return:
        """

        DirShootByAImage.up_shoot_image = pygame.image.load(up_image_path).convert_alpha()
        DirShootByAImage.down_shoot_image = pygame.image.load(down_image_path).convert_alpha()

    def __init__(self, path_name: str, image_width: int, image_height: int, is_loop: bool):
        super(DirShootByAImage, self).__init__(path_name, image_width, image_height, is_loop)
        self.__init_shoot("../Resources/images/shoot/up_shoot.png",
                          "../Resources/images/shoot/down_shoot.png")

    def get_image(self) -> pygame.Surface:
        """
        获取射击图片
        :return:
        """
        if self.shoot_dir == ShootDir.not_shoot:
            return None
        if self.shoot_dir < ShootDir.up:
            current_img = self.action_images[self.shoot_dir - 1][self.image_index]
            self.image_index += 1
            if self.image_index >= self.image_col:
                if self.is_loop:
                    self.image_index = 0
                else:
                    self.image_index = self.image_col - 1
        elif self.shoot_dir == ShootDir.up:
            current_img = DirShootByAImage.up_shoot_image
        else:
            current_img = DirShootByAImage.down_shoot_image
        return current_img

    def set_dir(self, dir: ShootDir):
        """
        获取射击方向
        :param dir:
        :return:
        """
        self.shoot_dir = dir
